import { createRouter, createWebHashHistory } from 'vue-router'


import Layout from '../views/main.vue'
import Login from '../views/login/index.vue'
import { el } from 'element-plus/es/locales.mjs'

const routes = [
    {
        path: '/',
        component: Layout,
        name: 'main',
        redirect: to => {
            //路由重定向
            const localDate = localStorage.getItem('ak_gl')
            if (localDate) {
                //有选中路由的情况下
                const path = JSON.parse(localDate).menuPath
                if (path) {
                    //跳转到选中路由
                    return path
                } else {
                    //否则跳到主控台
                    return '/dashboard'
                }
            } else {
                //无数据就跳到登录
                return '/login'
            }
        },
    },
    {
        path: '/login',
        component: Login
    },

]

const router = createRouter({
    routes,
    history: createWebHashHistory()
})




export default router